import 'package:flutter/material.dart';
import 'package:toastification/toastification.dart';

/// 简化版本的 Toastification 演示
/// 展示基本用法和核心功能
class SimpleToastExample extends StatelessWidget {
  const SimpleToastExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('简单 Toast 演示'),
        backgroundColor: Colors.blue.shade100,
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text(
                'Toastification 基础示例',
                style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(height: 32),
              
              // 成功提示
              _buildToastButton(
                context,
                '成功提示',
                Colors.green,
                () => _showSuccessToast(context),
              ),
              
              const SizedBox(height: 16),
              
              // 错误提示
              _buildToastButton(
                context,
                '错误提示',
                Colors.red,
                () => _showErrorToast(context),
              ),
              
              const SizedBox(height: 16),
              
              // 警告提示
              _buildToastButton(
                context,
                '警告提示',
                Colors.orange,
                () => _showWarningToast(context),
              ),
              
              const SizedBox(height: 16),
              
              // 信息提示
              _buildToastButton(
                context,
                '信息提示',
                Colors.blue,
                () => _showInfoToast(context),
              ),
              
              const SizedBox(height: 32),
              
              // 清除所有
              ElevatedButton(
                onPressed: () => toastification.dismissAll(),
                style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.grey,
                  foregroundColor: Colors.white,
                  minimumSize: const Size(200, 48),
                ),
                child: const Text('清除所有 Toast'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildToastButton(
    BuildContext context,
    String label,
    Color color,
    VoidCallback onPressed,
  ) {
    return ElevatedButton(
      onPressed: onPressed,
      style: ElevatedButton.styleFrom(
        backgroundColor: color,
        foregroundColor: Colors.white,
        minimumSize: const Size(200, 48),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(8),
        ),
      ),
      child: Text(label),
    );
  }

  void _showSuccessToast(BuildContext context) {
    toastification.show(
      context: context,
      type: ToastificationType.success,
      style: ToastificationStyle.fillColored,
      title: const Text('操作成功'),
      description: const Text('您的操作已成功完成！'),
      alignment: Alignment.topRight,
      autoCloseDuration: const Duration(seconds: 4),
      showProgressBar: true,
    );
  }

  void _showErrorToast(BuildContext context) {
    toastification.show(
      context: context,
      type: ToastificationType.error,
      style: ToastificationStyle.flat,
      title: const Text('操作失败'),
      description: const Text('操作失败，请检查您的输入并重试。'),
      alignment: Alignment.topRight,
      autoCloseDuration: const Duration(seconds: 4),
      showProgressBar: true,
    );
  }

  void _showWarningToast(BuildContext context) {
    toastification.show(
      context: context,
      type: ToastificationType.warning,
      style: ToastificationStyle.flatColored,
      title: const Text('操作警告'),
      description: const Text('请注意：此操作可能有风险。'),
      alignment: Alignment.topRight,
      autoCloseDuration: const Duration(seconds: 4),
      showProgressBar: true,
    );
  }

  void _showInfoToast(BuildContext context) {
    toastification.show(
      context: context,
      type: ToastificationType.info,
      style: ToastificationStyle.minimal,
      title: const Text('信息提示'),
      description: const Text('这是一个信息提示，为您提供有用的信息。'),
      alignment: Alignment.topRight,
      autoCloseDuration: const Duration(seconds: 4),
      showProgressBar: true,
    );
  }
}
